/**
 * desc: padding str with given filler
 * author: Joe
 * date: 7/27/2018
 *
 * @param {Number} length
 * @param {String|Number} filler
 * @param {String} direction, l/r
 */

coreModule.filter('padding', function() {
  return function(input, length, filler, direction) {
    if (!(angular.isNumber(input) || angular.isString(input))) {
      return input;
    }

    var str = String(input);
    filler = angular.isUndefined(filler) ? ' ' : filler;
    length = angular.isUndefined(length) ? 0 : length + 1;
    if (str.length < length) {
      var paddingLen = length - str.length;
      var paddingCtn = Array(paddingLen).join(filler);
      return direction === 'r' ? str + paddingCtn : paddingCtn + str;
    }

    return str;
  };
});
